package com.kaifamiao.io.d0921;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInputStreamDemo1 {

    public static void main(String[] args) {
        // 创建对象
        String path = "D:\\io\\file-input.txt";
        try (FileInputStream fileInputStream = new FileInputStream(path);) {

            long size = fileInputStream.available();
            System.out.println("还有 " + size + " 个字节未读取");
            int content = fileInputStream.read();
            System.out.println("读取到了一个字节: " + content);

            content = fileInputStream.read();
            System.out.println("读取到了一个字节: " + content);

            size = fileInputStream.available();
            System.out.println("还有 " + size + " 个字节未读取");

            // 跳过 2 个字节
            long skip = fileInputStream.skip(2);
            System.out.println("跳过了 " + skip + " 个字节");

            size = fileInputStream.available();
            System.out.println("还有 " + size + " 个字节未读取");

            content = fileInputStream.read();
            System.out.println("读取到了一个字节: " + content);

            size = fileInputStream.available();
            System.out.println("还有 " + size + " 个字节未读取");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
